from handle.register_handle import RegisterHandle

class RegisterBusiness:

    def __init__(self,driver):
        self.register_h = RegisterHandle(driver)


    def user_base(self,email,username,password,code):
        self.register_h.send_email(email)
        self.register_h.send_username(username)
        self.register_h.send_password(password)
        self.register_h.send_code(code)
        self.register_h.click_register_button()

    def register_success(self):

        if self.register_h.get_register_tesxt() == None:
            return  True
        else:
            return False

    def register_email_error(self,email,username,password,code):
        self.user_base(email,username,password,code)
        text = self.register_h.get_text('email_error','请输入有效的电子邮件地址')
        if self.register_h.get_text('email_error','请输入有效的电子邮件地址') == None:
            print('邮箱检验不成功')
            return True
        else:
            return False


    def register_name_error(self,email,username,password,code):
        self.user_base(email, username, password, code)
        if self.register_h.get_text('user_name_error', '字符长度必须大于等于4，一个中文字算2个字符') == None:
            print('用户名验证不成功')
            return True
        else:
            return False

    def register_password_error(self, email, username, password, code):
        self.user_base(email, username, password, code)
        if self.register_h.get_text('password_error', '最少需要输入 5 个字符') == None:
            print('密码验证不成功')
            return True
        else:
            return False

    def register_code_error(self, email, username, password, code):
        self.user_base(email, username, password, code)
        if self.register_h.get_text('code_error', '验证码错误') == None:
            print('验证码检查不成功')
            return True
        else:
            return False

    def register_function(self,email, username, password, code,assertCode,assertText):
        self.user_base(email, username, password, code)
        if self.register_h.get_text(assertCode, assertText) == None:
            return True
        else:
            return False
